package com.panda.business.task;

import com.panda.order.mapper.TPandaOrderBuyerMapper;
import com.panda.order.mapper.TPandaOrderHeadMapper;
import com.panda.order.mapper.TPandaOrderLineMapper;
import com.panda.quartz.mapper.SysJobLogMapper;
import com.panda.system.mapper.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;
import java.util.Date;

/**
 * 清理历史数据任务
 */
@Component("clearHisDataTask")
@Transactional
public class ClearHisDataTask {
    private static final Logger log = LoggerFactory.getLogger(ClearHisDataTask.class);
    private static final int DAY_CONF =-90;

    @Autowired
    private TPandaOrderBuyerMapper tPandaOrderBuyerMapper;
    @Autowired
    private TPandaOrderHeadMapper tPandaOrderHeadMapper;
    @Autowired
    private TPandaOrderLineMapper tPandaOrderLineMapper;

    @Autowired
    private PandaTaskDetailMapper pandaTaskDetailMapper;

    @Autowired
    private PandaTaskMapper pandaTaskMapper;

    @Autowired
    private PandaTaskMonitoringMapper pandaTaskMonitoringMapper;

    @Autowired
    private PandaWorkbenchMapper pandaWorkbenchMapper;

    @Autowired
    private TPandaEvalutionTaskMapper tPandaEvalutionTaskMapper;

    @Autowired
    private TPandaRebatesTaskMapper tPandaRebatesTaskMapper;

    @Autowired
    private TPandaTaskMapper tPandaTaskMapper;

    @Autowired
    private TPandaTaskUserMapper tPandaTaskUserMapper;

    @Autowired
    private SysJobLogMapper sysJobLogMapper;


    public void doClear(Date lastRun){
        log.info("清理历史数据开始！运行时间：{}",new Date());
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_YEAR, DAY_CONF);
        Date startTime = cal.getTime();
        log.info("清理{}前的数据。",startTime);
        tPandaOrderBuyerMapper.clearHisData(startTime);
        tPandaOrderHeadMapper.clearHisData(startTime);
        tPandaOrderLineMapper.clearHisData(startTime);
        pandaTaskDetailMapper.clearHisData(startTime);
        pandaTaskMapper.clearHisData(startTime);
        pandaTaskMonitoringMapper.clearHisData(startTime);
        tPandaEvalutionTaskMapper.clearHisData(startTime);
        tPandaRebatesTaskMapper.clearHisData(startTime);
        tPandaTaskMapper.clearHisData(startTime);
        tPandaTaskUserMapper.clearHisData(startTime);
        pandaWorkbenchMapper.clearHisData(startTime);
        sysJobLogMapper.clearHisData(startTime);
        log.info("清理历史数据完成！运行时间：{}",new Date());
    }

}
